VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "itgcontrols.ocx"
Begin VB.Form frmMaintTruckerRoute 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   3540
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   7995
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   3540
   ScaleWidth      =   7995
   ShowInTaskbar   =   0   'False
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   255
      Left            =   0
      TabIndex        =   0
      Top             =   3285
      Width           =   7995
      _ExtentX        =   14102
      _ExtentY        =   450
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   2
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
      EndProperty
   End
   Begin ITGControls.ITGTab SSTab1 
      Height          =   2055
      Left            =   0
      TabIndex        =   8
      Top             =   1050
      Width           =   7830
      _ExtentX        =   13811
      _ExtentY        =   3625
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   8
      Tab(0)ContCtrlCap(1)=   "txtDestination"
      Tab(0)ContCtrlCap(2)=   "txtKM"
      Tab(0)ContCtrlCap(3)=   "txtOrigin"
      Tab(0)ContCtrlCap(4)=   "txtRouteCode"
      Tab(0)ContCtrlCap(5)=   "Timer1"
      Tab(0)ContCtrlCap(6)=   "cmdPickOrigin"
      Tab(0)ContCtrlCap(7)=   "cmdPickDestination"
      Tab(0)ContCtrlCap(8)=   "Shape2"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   16243138
      DisabledTabForeColor=   -2147483630
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   1740
         Left            =   -75000
         TabIndex        =   7
         TabStop         =   0   'False
         Top             =   315
         Width           =   7830
         _ExtentX        =   13811
         _ExtentY        =   3069
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   4
         BeginProperty Column00 
            DataField       =   "cRouteCode"
            Caption         =   "Route ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cOrigin"
            Caption         =   "Origin"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cDestination"
            Caption         =   "Destination"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "nKM"
            Caption         =   "KM"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1244.976
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   2099.906
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   2099.906
            EndProperty
            BeginProperty Column03 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1365.165
            EndProperty
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtDestination 
         Height          =   285
         Left            =   480
         TabIndex        =   4
         Top             =   1170
         Width           =   6540
         _ExtentX        =   11324
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14745599
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Label           =   "Destination"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1410
         TextBoxWidth    =   5070
         Required        =   -1  'True
      End
      Begin ITGControls.ITGTextBox txtKM 
         Height          =   285
         Left            =   480
         TabIndex        =   6
         Top             =   1485
         Width           =   2895
         _ExtentX        =   4895
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "KM"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1410
         TextBoxWidth    =   1425
         Required        =   -1  'True
      End
      Begin ITGControls.ITGTextBox txtOrigin 
         Height          =   285
         Left            =   480
         TabIndex        =   2
         Top             =   855
         Width           =   6540
         _ExtentX        =   11324
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14745599
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Label           =   "Origin"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1410
         TextBoxWidth    =   5070
         Required        =   -1  'True
      End
      Begin ITGControls.ITGTextBox txtRouteCode 
         Height          =   285
         Left            =   480
         TabIndex        =   1
         Top             =   540
         Width           =   2880
         _ExtentX        =   4868
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14745599
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Label           =   "Route ID"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1410
         TextBoxWidth    =   1410
         TextTrim        =   -1  'True
         Required        =   -1  'True
      End
      Begin VB.Timer Timer1 
         Interval        =   300
         Left            =   3375
         Top             =   465
      End
      Begin VB.CommandButton cmdPickOrigin 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   300
         Left            =   7065
         Picture         =   "frmMaintTruckerRoute.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   3
         Top             =   855
         Width           =   315
      End
      Begin VB.CommandButton cmdPickDestination 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   300
         Left            =   7050
         Picture         =   "frmMaintTruckerRoute.frx":014A
         Style           =   1  'Graphical
         TabIndex        =   5
         Top             =   1170
         Width           =   315
      End
      Begin VB.Shape Shape2 
         BorderColor     =   &H00404040&
         Height          =   1740
         Left            =   0
         Top             =   315
         Width           =   7830
      End
   End
   Begin VB.Image imgLogo 
      BorderStyle     =   1  'Fixed Single
      Height          =   930
      Left            =   6720
      Stretch         =   -1  'True
      Top             =   0
      Width           =   1125
   End
   Begin VB.Shape Shape1 
      BorderColor     =   &H00404040&
      Height          =   975
      Left            =   0
      Top             =   0
      Width           =   6630
   End
   Begin VB.Label lblHeader 
      BackColor       =   &H00F7D9C2&
      BackStyle       =   0  'Transparent
      Caption         =   "Route ID - Origin - Destination"
      BeginProperty Font 
         Name            =   "Tahoma"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   180
      TabIndex        =   10
      Top             =   195
      Width           =   8835
   End
   Begin VB.Label lblDetails 
      BackColor       =   &H00F7D9C2&
      BackStyle       =   0  'Transparent
      Caption         =   "Trucker Route"
      ForeColor       =   &H00000000&
      Height          =   255
      Left            =   180
      TabIndex        =   9
      Top             =   555
      Visible         =   0   'False
      Width           =   9150
   End
End
Attribute VB_Name = "frmMaintTruckerRoute"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

'Object variables





'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1

'ADO Connection variables

Private connHeader As ADODB.Connection

'Form mode enumeration
Public Enum eRouteMode
    Normal
    AddNewEdit
    Find
End Enum
Private Mode As eRouteMode

'Other declaration
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtRouteCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cRouteCode LIKE '" & Trim$(txtRouteCode.Text) & "%'"
    End If

    If Trim$(txtOrigin.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cOrigin LIKE '" & Trim$(txtOrigin.Text) & "%'"
    End If
    
    If Trim$(txtDestination.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cDestination LIKE '" & Trim$(txtDestination.Text) & "%'"
    End If
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

Private Sub cmdPickDestination_Click()
    If lPickListActive Then Exit Sub
    frmITGPicker.zType = QLocation
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'" 'added gino
    frmITGPicker.Show vbModal
    txtDestination = frmITGPicker.zName
    If Trim(txtDestination) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickOrigin_Click()
    If lPickListActive Then Exit Sub
    frmITGPicker.zType = QLocation
    frmITGPicker.Condition = "where cCompanyID = '" & COID & "'" ' added gino
    frmITGPicker.Show vbModal
    txtOrigin = frmITGPicker.zName
    If Trim(txtOrigin) <> "" Then SendKeys "{Tab}"
End Sub

'Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
'    SortGrid dtgList, ColIndex, rsHeader
'End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()
        
    Set FrmName = Me
    FormSetup
    
    AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'MF23'")
    
    Set rsHeader = New ADODB.Recordset
    
    
    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    
    imgLogo.Picture = ITGLedgerMain.Picture1.Picture
    Mode = Find
    txtRouteCode.Locked = False
   
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    
    
    
    
    
    Set rsHeader = Nothing
    Set connHeader = Nothing
    
    Set frmMaintTruckerRoute = Nothing

    lCloseWindow = True
    
'    'oForm(Me.Tag).Mode = 1
'    'oForm(Me.Tag).Tag = Me.Tag
End Sub

'Add new record to the recordset
Public Sub TBNew()
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , True, True, , , , True
    txtRouteCode.BackColor = &HE0FFFF
    Mode = AddNewEdit
    
    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenRecordsetWithCN rsHeader, "*", "TRUCKER_ROUTE", connHeader, "WHERE 1 = 0 "
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If
    
    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!cRouteCode = LatestCode
    
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    SSTab1.ActiveTab = 0
    txtRouteCode.Locked = True
    txtOrigin.SetFocus

End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
    Else
        RSZero
        Mode = Find
    End If
    
    sbRS.Panels(2) = ""

    SetDataSource
    SetDataField

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    If rsHeader.Status = adRecNew Then
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then lBoolean = True

    
    If Not MandatoryOK Then Exit Sub

    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    
    rsHeader.UpdateBatch adAffectAll
    
    cn.CommitTrans
    connHeader.CommitTrans
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
    Mode = Normal

    MsgBox "Record/s successfully saved.", vbInformation, "iTG Finance Manager"
    SetDataSource
    
    'Audit trail
    UpdateLogFile "Trucker Route", Trim(txtRouteCode), IIf(lBoolean, "Inserted", "Updated")
    
    lblHeader = rsHeader!cRouteCode & " - " & rsHeader!cOrigin & " - " & rsHeader!cDestination & ""
    sbRS.Panels(2) = ""

ErrHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connHeader.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "iTG Finance Manager"
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "iTG Finance Manager"
        cn.RollbackTrans
        connHeader.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
'    If GetValueFrTable("cRouteCode", "TRUCKER_RATE", "cRouteCode = '" & Trim(txtRouteCode) & "'") <> "" Then
'        MsgBox "Route was referenced by Truck Rate. Edit is not allowed.", vbExclamation, "iTG Finance Manager"
'        Exit Sub
'    End If
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtRouteCode.Locked = True
    SSTab1.ActiveTab = 0
    txtOrigin.SetFocus
    vBM = rsHeader.Bookmark
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub
    
    If GetValueFrTable("cRouteCode", "V_RouteRef", "cRouteCode = '" & Trim(txtRouteCode) & "'") <> "" Then
        MsgBox "Route was referenced. Deletion is not allowed.", vbExclamation, "iTG Finance Manager"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "iTG Finance Manager") = vbNo Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Trucker Route", Trim(txtRouteCode), "Deleted"

    rsHeader.Delete adAffectCurrent
    rsHeader.UpdateBatch adAffectAll

    TBPrevRec

    Mode = Normal
    
    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtRouteCode.Locked = True
    frmITGSearch.Show
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
            
    OpenNewConnection connHeader
    
    Set rsHeader = Nothing
    Set rsHeader = New ADODB.Recordset
            
    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtRouteCode.Locked = False
        txtRouteCode.SetFocus
        Exit Sub
    End If
    
    OpenRecordsetWithCN rsHeader, "*", "TRUCKER_ROUTE", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
            
    Set FrmName = Me
    FormLocking True
            
    If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtRouteCode.BackColor = &HE0FFFF
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True

    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
    
End If

End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader

End Sub

'Move previous
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader

End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader

End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader

End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    'Not available for this module
End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
    'Not avilable for this module
End Sub

'Undo all
Public Sub TBUndoLineAll()
    'Not available for this module
End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    'Not available for this module
End Sub

'Post current record
Public Sub TBPostRecord()
    'Not available for this module
End Sub

'Cancel current record
Public Sub TBCancelRecord()
    'Not available for this module
End Sub

'Print
Public Sub TBPrintRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader

End Sub
    
'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtRouteCode.DataField = !cRouteCode
        txtOrigin.DataField = !cOrigin
        txtDestination.DataField = !cDestination
        txtKM.DataField = !nKM
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler
    
    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        lblHeader = rsHeader!cRouteCode & " - " & rsHeader!cOrigin & " - " & rsHeader!cDestination & ""
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount
        
        If rsHeader.Status <> adRecNew Then
            txtRouteCode.Locked = True
        Else
            txtRouteCode.Locked = False
        End If
        
        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
    Else
        lblHeader = "Route ID - Origin - Destination"
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtRouteCode.Locked = False
    End If
    
ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If
    
End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtDestination_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If GetValueFrTable("cLocation", "LOCATION", "cLocation = '" & Trim(txtDestination) & "'") = "" Then cmdPickDestination_Click
End Sub

Private Sub txtOrigin_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If GetValueFrTable("cLocation", "LOCATION", "cLocation = '" & Trim(txtOrigin) & "'") = "" Then cmdPickOrigin_Click
End Sub

Private Sub txtRouteCode_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    KeyAscii = ValidKeys(KeyAscii, "1234567890", True)
End Sub

Private Sub txtRouteCode_LostFocus()
    'Does Code Already exists
    If Mode = AddNewEdit Then
        If Trim(txtRouteCode) = "" Then
            MsgBox "Empty primary input.", vbInformation, "iTG Finance Manager"
            txtRouteCode.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtRouteCode = Trim(txtRouteCode)
            If IDExisting(rsHeader, "cRouteCode", "TRUCKER_ROUTE", Trim(rsHeader!cRouteCode)) Then
                MsgBox "Route ID already exists.", vbInformation, "iTG Finance Manager"
                txtRouteCode.SetFocus
            End If
        End If
    End If
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean
    
    MandatoryOK = True
    
    If Trim(txtRouteCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Route ID' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        txtRouteCode.SetFocus
        Exit Function
    End If
    
    If rsHeader.Status = adRecNew Then
        If IDExisting(rsHeader, "cRouteCode", "TRUCKER_ROUTE", Trim(rsHeader!cRouteCode)) Then
            MandatoryOK = False
            MsgBox "Route ID already exists.", vbInformation, "iTG Finance Manager"
            txtRouteCode.SetFocus
            Exit Function
        End If
    End If
        
    If Trim(txtOrigin) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Origin' is mandatory. Null value is not allowed", vbInformation, "iTG Finance Manager"
        txtOrigin.SetFocus
        Exit Function
    ElseIf Trim(txtDestination) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Destination' is mandatory. Null value is not allowed", vbInformation, "iTG Finance Manager"
        txtDestination.SetFocus
        Exit Function
    ElseIf CDbl(txtKM) = 0 Then
        MandatoryOK = False
        MsgBox "Field 'KM' is mandatory. Null or zero value is not allowed", vbInformation, "iTG Finance Manager"
        txtKM.SetFocus
        Exit Function
    End If
    
End Function

'Sets the form if record number is zero
Private Sub RSZero()
    lblHeader = "Route ID - Origin - Destination"
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtRouteCode.Locked = False
    txtRouteCode.SetFocus
    
    Mode = Find
End Sub

Sub SearchObj(lEnable As Boolean)
    cmdPickOrigin.Enabled = lEnable
    cmdPickDestination.Enabled = lEnable
End Sub

'Auto Number
Public Function LatestCode() As String
On Error GoTo TheSource

Dim CurYear As String, sYear As String
Dim rs As New Recordset
    
    CurYear = DatePart("yyyy", Date)
    sSQL = "SELECT cRouteCode FROM TRUCKER_ROUTE ORDER BY cRouteCode"
    Set rs = New Recordset
    rs.Open sSQL, cn, adOpenKeyset
    
    If rs.RecordCount > 0 Then
        rs.MoveLast
        sYear = Mid(rs!cRouteCode, 1, 4)
        If CDec(sYear) <> CurYear Then
            sYear = 0
            LatestCode = CurYear & "0001"
        Else
            LatestCode = CurYear & Format(Right(Trim(rs!cRouteCode), 4) + 1, "0000")
        End If
    Else
        LatestCode = CurYear & "0001"
    End If
    
    Set rs = Nothing

TheSource:
    If err.Number <> 0 Then
        If rs.State = adStateOpen Then Set rs = Nothing
        Exit Function
    End If
End Function


'Public Sub ShowForm(sTranNo As String)
'    If Mode = Find Then
'
'        OpenNewConnection connHeader
'
'        Set rsHeader = Nothing
'        Set rsHeader = New ADODB.Recordset
'
'        OpenRecordsetWithCN rsHeader, "*", "TRUCKER_ROUTE", connHeader, "WHERE cRouteCode = '" & Trim(sTranNo) & "'"
'
'        Set FrmName = Me
'        FormLocking True
'
'        If rsHeader.RecordCount = 0 Then
'            FormWaitHide
'            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
'            RSZero
'            FormSearch True
'            SearchObj True
'            Mode = Find
'            Exit Sub
'        End If
'            SetDataSource
'            SetDataField
'            txtRouteCode.BackColor = &HE0FFFF
'            Mode = Normal
'            oBar.BitEnabled Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True
'
'    End If
'End Sub



